package com.simin.base.appdialog;



import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.annotation.LayoutRes;

import com.simin.base.R;
import com.google.android.material.bottomsheet.BottomSheetDialog;
/**
 * date:2023/9/25
 * author:wangsimin
 * funcation:底部弹窗
 */
public class BottomDialogManager {
    /**
     * show底部弹窗dialog
     *
     * @param context            上下文
     * @param layoutId           res布局文件
     * @param onBindViewCallback bind视图的回调
     * @return dialog
     */
    public static Dialog buildBottomSheetDialog(Activity context, @LayoutRes int layoutId, OnBindViewCallback onBindViewCallback) {
        BottomSheetDialog mDialog = new BottomSheetDialog(context, R.style.DialogTheme);
        View view = View.inflate(context, layoutId, null);
        mDialog.setContentView(view);
        Window window = mDialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.main_menu_animStyle);
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        if (onBindViewCallback != null) {
            onBindViewCallback.onBindView(view, mDialog);
        }
        if (!context.isFinishing()) {
            mDialog.show();
        }
        return mDialog;
    }


    public interface OnBindViewCallback {
        void onBindView(View view, Dialog dialog);
    }

}
